import { getHome } from 'services/home';

export default {

    namespace: 'home',

    state: {
        list:[]
    },

    subscriptions: {
        setup ({ dispatch, history }) {
          history.listen((location) => {
            if (location.pathname === '/') {
                dispatch({
                  type: 'getHome',
                  payload:{
                  }
                })
             
            }
          })  
          
        }
    },
    effects : {
      *getHome ({ payload }, { call, put }) {
        const homeList = yield call(getHome, payload);
        if(homeList.data){
          yield put({
            type: 'save',
            payload:{
              list:homeList.data
            }
          })
        }
       
      },
    },
    reducers : {
      save (state, action) {
        return {
          ...state,
          ...action.payload
        }
      },
    }

}
